/**
 * ]~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~._
 * ]~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~._ 
 *
 * @file		:	TreknoBabbleViewController.h		
 * @name		: 	TreknoBabble
 * 
 * @author	:	Matt Holcombe (gullinbursti)
 * @date		:	10-29-10
 * 
 * @brief	:	Implementation of the app's view controller.	
 *
 * ]~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~·¯
 * ]~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~·¯
 **/


//] includes [!]>
//]=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~.
#import "TreknoBabbleViewController.h"

#import "FontLabel.h"
#import "FontLabelStringDrawing.h"
#import "FontManager.h"
//]~=~=~=~=~=~=~=~=~=~=~=~=~=~[]~=~=~=~=~=~=~=~=~=~=~=~=~=~[


// <[!] class delaration [¡]>
@implementation TreknoBabbleViewController

@synthesize lblDialog;

@synthesize arrAuxVerb;
@synthesize arrActVerb;
@synthesize arrSubject;
@synthesize arrDative;
@synthesize arrTransVerb;
@synthesize arrAdjNoun;
@synthesize arrPreposition;
@synthesize arrLocNoun;
@synthesize arrSupVerb;
@synthesize arrSupNoun;
@synthesize arrSubAdpos;

@synthesize strSolution;


- (void)loadView {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> loadView() <[-]>");
	
	[super loadView];
	
	// setup label
	lblDialog = [[FontLabel alloc] initWithFrame:CGRectMake(16, 16, 288, 320) fontName:@"tngtitle" pointSize:24.0f];
	lblDialog.textColor = [UIColor darkGrayColor];
	lblDialog.text = @"Wesley, we need a solution!";
	lblDialog.textAlignment = UITextAlignmentCenter;
	lblDialog.lineBreakMode = UILineBreakModeTailTruncation;
	lblDialog.backgroundColor = nil;
	lblDialog.opaque = NO;
	lblDialog.numberOfLines = 0;
	
	[self.view addSubview:lblDialog];
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


- (void)viewDidLoad {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> viewDidLoad() <[-]>");
	
	// load up the plist
	NSDictionary *dicContents = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"VerbageDict" ofType:@"plist"]];
	NSArray *arrVerbage = [[dicContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
	
	
	// each part
	self.arrAuxVerb = [dicContents objectForKey:[arrVerbage objectAtIndex:0]];
	self.arrActVerb = [dicContents objectForKey:[arrVerbage objectAtIndex:1]];
	self.arrSubject = [dicContents objectForKey:[arrVerbage objectAtIndex:2]];
	self.arrDative = [dicContents objectForKey:[arrVerbage objectAtIndex:3]];
	self.arrTransVerb = [dicContents objectForKey:[arrVerbage objectAtIndex:4]];
	self.arrAdjNoun = [dicContents objectForKey:[arrVerbage objectAtIndex:5]];
	self.arrPreposition = [dicContents objectForKey:[arrVerbage objectAtIndex:6]];
	self.arrLocNoun = [dicContents objectForKey:[arrVerbage objectAtIndex:7]];
	self.arrSupVerb = [dicContents objectForKey:[arrVerbage objectAtIndex:8]];
	self.arrSupNoun = [dicContents objectForKey:[arrVerbage objectAtIndex:9]];
	self.arrSubAdpos = [dicContents objectForKey:[arrVerbage objectAtIndex:10]];
	
	
	// kill dictionary
	[dicContents release];
	
	
	[super viewDidLoad];
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


- (void)didReceiveMemoryWarning {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> didReceiveMemoryWarning() <[-]>");
	
	// releases the view if it doesn't have a superview.
	[super didReceiveMemoryWarning];
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


- (void)viewDidUnload {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> viewDidUnload() <[-]>");
	
	// label
	self.lblDialog = nil;
	
	// verbage arrays
	self.arrAuxVerb = nil;
	self.arrActVerb = nil;
	self.arrSubject = nil;
	self.arrDative = nil;
	self.arrTransVerb = nil;
	self.arrAdjNoun = nil;
	self.arrPreposition = nil;
	self.arrLocNoun = nil;
	self.arrSupVerb = nil;
	self.arrSupNoun = nil;
	self.arrSubAdpos =nil;
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


- (void)dealloc {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> dealloc() <[-]>");
	
	// label
	[lblDialog release];
	
	// verbage arrays
	[arrAuxVerb release];
	[arrActVerb release];
	[arrSubject release];
	[arrDative release];
	[arrTransVerb release];
	[arrAdjNoun release];
	[arrPreposition release];
	[arrLocNoun release];
	[arrSupVerb release];
	[arrSupNoun release];
	[arrSubAdpos release];
	
	
	[super dealloc];
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯





- (IBAction)hdlGenerateBtn_ReleaseInside:(id)sender {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> hdlGenerateBtn_ReleaseInside() <[-]>");
	
	// prime
	strSolution = [[NSString alloc] initWithFormat:@"You "];
	[self generateSolution];
	
	// set caption
	lblDialog.text = strSolution;
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯




- (void)generateSolution {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	NSLog(@"<[-]> generateSolution() <[-]>");
	
	int ind;
	NSString *strSupVerbage = [[NSString alloc] initWithString:@""];
	
	
	// 1st two parts
	strSolution = [strSolution stringByAppendingFormat:@"%@ ", [arrAuxVerb objectAtIndex:[self rndIndex:[arrAuxVerb count]]]];
	strSolution = [strSolution stringByAppendingFormat:@"%@ ", [arrActVerb objectAtIndex:[self rndIndex:[arrActVerb count]]]];
	
	
	// index to the 3rd
	ind = [self rndIndex:[arrSubject count]];
	
	// prefix
	if (ind >= 11)
		strSolution = [strSolution stringByAppendingFormat:@"%@ ", [arrSupVerb objectAtIndex:[self rndIndex:[arrSupVerb count]]]];
	
	// add on 3rd part
	strSolution = [strSolution stringByAppendingFormat:@"%@", [arrSubject objectAtIndex:ind]];
	
	// make suffix
	if (ind >= 8) {
		strSupVerbage = [[NSString alloc] initWithFormat:@" %@ ", [arrSubAdpos objectAtIndex:[self rndIndex:[arrSubAdpos count]]]];
		
		// make suffix 2
		if (ind == 11 || ind >= 13)
			strSupVerbage = [[NSString alloc] initWithFormat:@"%@%@", [arrSupNoun objectAtIndex:[self rndIndex:[arrSupNoun count]]], strSupVerbage];
	}
	
	// add sufixes
	strSolution = [strSolution stringByAppendingFormat:@"%@", strSupVerbage];
	
	// add the rest
	strSolution = [strSolution stringByAppendingFormat:@"%@ to ", [arrDative objectAtIndex:[self rndIndex:[arrDative count]]]];
	strSolution = [strSolution stringByAppendingFormat:@"%@ ", [arrTransVerb objectAtIndex:[self rndIndex:[arrTransVerb count]]]];
	strSolution = [strSolution stringByAppendingFormat:@"%@ ", [arrAdjNoun objectAtIndex:[self rndIndex:[arrAdjNoun count]]]];
	strSolution = [strSolution stringByAppendingFormat:@"%@ the ", [arrPreposition objectAtIndex:[self rndIndex:[arrPreposition count]]]];
	strSolution = [strSolution stringByAppendingFormat:@"%@!", [arrLocNoun objectAtIndex:[self rndIndex:[arrLocNoun count]]]];
	
	
	// cleanup
	[strSupVerbage release];
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


- (int)rndIndex:(int)length {
//~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~~*~._
	//NSLog(@"<[-]> rndIndex(%d) <[-]>", length);
	
	return rand() % length;
}//]~*~~*~~*~~*~~*~~*~~*~~*~~·¯


@end
